#include <stdio.h>
#include <unistd.h>
#include "threadpool.h"

void* process(void* arg)
{
    printf("thread 0x%x working on task %d\n", (unsigned int)pthread_self(), *(int*)arg);
    sleep(1);
    printf("task %d is end\n", *(int*)arg);
    return NULL;
}

int main(int argc, char const *argv[])
{
    /*threadpool_t* threadpool_create(int min_thr_num, int max_thr_num, int queue_max_size)*/
    threadpool_t *thp = threadpool_create(3, 100,100);/*创建线程池,池里面最小3个线程,最大100,队列最大100*/

    // int *num = (int *)malloc(sizeof(int)*20);
    int num[20], i;
    for ( i = 0; i < 20; i++){
        num[i] = i;
        threadpool_add(thp, process, (void*)&num[i]); /*向线程池中添加任务*/
    }
    sleep(10);
    threadpool_destroy(thp); /*等待子线程完成任务*/
    return 0;
}
